<?php
/* @var $this ActivityDetailController */
/* @var $model ActivityDetail */

$this->breadcrumbs=array(
	'[活动明细]管理'=>array('admin'),
	'修改[活动明细]',
);
//设置页面标题
$this->pageTitle=Yii::app()->name.' - 修改[活动明细]';
$this->contentTitle='修改[活动明细]';
?>

<!--表单内容-->
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'activity-detail-form',
	'enableAjaxValidation'=>false,
        'enableClientValidation'=>true,
        'clientOptions'=>array(
            'validateOnSubmit'=>true
        ),
    'htmlOptions'=>array('class'=>'ajax_form'),
)); ?>
    <link type="text/css" href="<?php echo Yii::app()->baseUrl?>/css/jquery-ui-1.8.17.custom.css" rel="stylesheet" />
    <link type="text/css" href="<?php echo Yii::app()->baseUrl?>/css/jquery-ui-timepicker-addon.css" rel="stylesheet" />
    <script type="text/javascript" src="<?php echo Yii::app()->baseUrl?>/js/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="<?php echo Yii::app()->baseUrl?>/js/jquery-ui-1.8.17.custom.min.js"></script>
    <script type="text/javascript" src="<?php echo Yii::app()->baseUrl?>/js/jquery-ui-timepicker-addon.js"></script>
    <script type="text/javascript" src="<?php echo Yii::app()->baseUrl?>/js/jquery-ui-timepicker-zh-CN.js"></script>
    <style type="text/css">
        .none
        {
            display: none;
        }
        .nTab .TabTitle li
        {
            float: left;
            cursor: pointer;
            width: 100px;
            height: 35px;
            line-height: 35px;
            font-weight: bold;
            text-align: center;
            border: 1px solid #333;
        }
        .nTab .TabTitle li a
        {
            text-decoration: none;
        }
        .nTab .TabTitle .active
        {
            background: #DEDEDE;
        }

    </style>

<table>
	<tr>
		<td><?php echo $form->labelEx($model,'is_float'); ?></td>
                <td>
			<?php echo $form->dropDownList($model,'is_float',array('0'=>'闭馆','1'=>'开馆','2'=>'团体','3'=>'报名已满'),
                                array('style'=>'float: left;')); ?> 
			<?php echo $form->error($model,'is_float'); ?>
		</td>
		<td><?php echo $form->labelEx($model,'activity_id'); ?></td>
                <td>
			 <?php echo $form->dropDownList($model,'activity_id',CHtml::listData(Activity::model()->findAll(), 'id', 'title'),
                                array('empty'=>'-----请选择----','style'=>'float: left;')); ?> 
			<?php echo $form->error($model,'activity_id'); ?>
		</td>  
		<td><?php echo $form->labelEx($model,'crowd_id'); ?></td>
		<td>
			<?php echo $form->dropDownList($model,'crowd_id',CHtml::listData(Crowd::model()->findAll(), 'id', 'title'),
                                array('empty'=>'-----请选择----','style'=>'float: left;')); ?> 
			<?php echo $form->error($model,'crowd_id'); ?>
		</td> 
                 <td><?php echo $form->labelEx($model,'begins'); ?></td>
		<td>
			<?php  
                        $this->widget('zii.widgets.jui.CJuiDatePicker', array(  
                            'model'=>$model,  
                            'attribute'=>'begins', 
                            'language'=>'zh_cn',
                            'options' => array(  
                            'dateFormat'=>'yy-mm-dd', //database save format  
                                //'altFormat'=>'mm-dd-yy' //display format  
                                //'showAnim'=>'fold',  
                                //'yearRange'=>'-3:+3'   
                            ),  
                            'htmlOptions'=>array(  
                                 'value'=>substr($model->begins, 0,10),  
                                'readonly'=>'readonly',  
                                'style'=>'width:150px;',  
                            )  
                        ));?>  
			<?php echo $form->error($model,'begins'); ?>
		</td>
		            
	</tr>
        <tr>
                <td ><?php echo $form->labelEx($model,'start'); ?></td>
		<td>
                        <input class="fl input" style="width:150px;" value="<?php echo $model->start; ?>" id="ActivityDetail_start" name="ActivityDetail[start]" type="text">
			<?php echo $form->error($model,'start'); ?>
		</td>  
		<td><?php echo $form->labelEx($model,'end'); ?></td>
		<td>
			<input class="fl input" style="width:150px;" id="ActivityDetail_end" value="<?php echo $model->end; ?>" name="ActivityDetail[end]" type="text"> 
			<?php echo $form->error($model,'end'); ?>
		</td>  
                <td><?php echo $form->labelEx($model,'clander_start'); ?></td>
		<td>
			<input class="fl input" style="width:150px;" id="ActivityDetail_clander_start" value="<?php echo $model->clander_start; ?>" name="ActivityDetail[clander_start]" type="text"> 
			<?php echo $form->error($model,'clander_start'); ?>
		</td>
		<td><?php echo $form->labelEx($model,'clander_end'); ?></td>
		<td>
			<input class="fl input" style="width:150px;" id="ActivityDetail_clander_end" value="<?php echo $model->clander_end; ?>" name="ActivityDetail[clander_end]" type="text"> 
			<?php echo $form->error($model,'clander_end'); ?>
		</td>
               
        </tr>
	<tr>
		
		<td><?php echo $form->labelEx($model,'astrict'); ?></td>
		<td>
			<?php echo $form->textField($model,'astrict',array('size'=>6,'maxlength'=>255,'class'=>'fl input')); ?>
			<?php echo $form->error($model,'astrict'); ?>
		</td>
<!--		<td>短信</td>
		<td>
			<?php /*
                            if($sms_model==null){
                                $sms_model=new Sms;
                            }
                            echo $form->dropDownList($sms_model,'id',CHtml::listData(Sms::model()->findAll('is_type=1'), 'id', 'activity.title'),
                                array('empty'=>'-----请选择----','style'=>'float: left;')); */?> 
			<?php /*echo $form->error($sms_model,'id'); */?>
		</td>-->
                <!-- 已报名人数 -->
		<td>已报名人数：</td>
		<td style="text-align: center;">    
                    <?php echo $num_1; ?>
		</td>  
                
                <!-- 已审核人数 -->
		<td>已审核人数：</td>
                <td style="text-align: center;">    
                    <?php echo $num_2; ?>
		</td> 
                <?php
                    $invitation_code=$model->invitation_code;
                    if ($invitation_code!=''){
                        echo '<td>团队邀请码：</td>';
                        echo '<td style="text-align: center;">'.$invitation_code.'</td> ';
                    }
                ?>
<!--                <td>团队邀请码：</td>
                <td style="text-align: center;">    
                    <?php echo $model->invitation_code; ?>
		</td>     -->
	</tr> 
       
        <tr style="display: none;">
		<td align="right"><?php echo $form->labelEx($model,'remark'); ?></td>
		<td>
			<?php echo $form->textArea($model,'remark',array('rows'=>6, 'cols'=>50,'class'=>'fl input')); ?>
			<?php echo $form->error($model,'remark'); ?>
		</td>
		<td align="right"><?php echo $form->labelEx($model,'is_state'); ?></td>
		<td>
			<?php echo $form->textField($model,'is_state',array('class'=>'fl input')); ?>
			<?php echo $form->error($model,'is_state'); ?>
		</td>                
	</tr>
</table>
<div>
        <!-- 车辆 -->
    <table>
        <tr id="ch">
        <?php
        $line_count= count($line_model);
        $line_index=1;
        ?>
        <td>安排</td>            
        <?php   
        foreach ($line_model as $value) {
        ?> 
            <td id="add_lines_<?php echo 'model_'.$value->id; ?>">
                <div>
                    <table style="background: #F0F0F0;" >
                        <tr style="display: none;">
                            <td colspan="2">
                                <input class="fl input" name="LineDetail_id_<?php echo $line_index-1; ?>" id="LineDetail_id" type="text" value="<?php echo $value->id; ?>">
                            </td>
                        </tr>   
<!--                        <tr style="background: #F0F0F0;">
                            <td></td>
                            <td align="right"><image onclick="clear_div('model_<?php echo $value->id; ?>')" style="width:1.5em; margin-left: 15em;"src=" <?php echo Yii::app()->baseUrl?>/images/del.png" /></td>
                        </tr>   -->
                        <tr style="background: #F0F0F0;">
                            <td align="right"><?php echo $form->labelEx($value,'car_id'); ?></td>
                            <td>
                                <?php echo $form->dropDownList($value,'car_id[]',CHtml::listData(Carinfo::model()->findAll(), 'id', 'code'),
                                    array('options'=>array($value->car_id=>array('selected'=>true)),'empty'=>'-----请选择----','style'=>'float: left;')); ?>                                 
                                <?php echo $form->error($value,'car_id'); ?>
                            </td>
                        </tr>

                        <tr style="background: #F0F0F0;">
                            <td align="right"><?php echo $form->labelEx($value,'go_time'); ?></td>
                            <td>
                                <?php echo $form->textField($value,'go_time[]',array('value'=>$value->go_time,'size'=>15,'maxlength'=>255,'class'=>'fl input')); ?>
                                <?php echo $form->error($value,'go_time'); ?>
                                <!--<input class="fl input" style="width:150px;" value="<?php echo $value->go_time; ?>" id="<?php echo 'go_time_model_'.$line_index; ?>" name="LineDetail[go_time][]" type="text">-->
                                
                            </td>
                        </tr>

                        <tr style="background: #F0F0F0;">
                            <td align="right"><?php echo $form->labelEx($value,'position_id'); ?></td>
                            <td>
                                <?php echo $form->dropDownList($value,'position_id[]',CHtml::listData(Position::model()->findAll(), 'id', 'address'),
                                    array('options'=>array($value->position_id=>array('selected'=>true)), 'empty'=>'-----请选择----','style'=>'float: left;')); ?> 
                                <?php echo $form->error($value,'position_id'); ?>
                            </td>
                        </tr>

                        <tr style="background: #F0F0F0;">
                            <td align="right"><?php echo $form->labelEx($value,'staff'); ?></td>
                            <td>
                                <?php echo $form->dropDownList($value,'staff[]',CHtml::listData(Staff::model()->findAll(), 'id', 'username'),
                                    array('options'=>array($value->staff=>array('selected'=>true)), 'empty'=>'-----请选择----','style'=>'float: left;')); ?> 
                                <?php echo $form->error($value,'staff'); ?>
                            </td>
                        </tr>
                    </table>   
                </div>                    
            </td>                
                                          
        <?php
        $line_index+=1;
         }
        ?>
<!--            <td  id="ch_list" style=" width:2em;text-align: center;"><image  onclick="addList()" style="width:1.5em;"src=" <?php echo Yii::app()->baseUrl?>/images/u44.png" /></td>-->
        </tr>       
    </table>
        <div class="errorMessage" id="Line_detail_em_" ></div>
        <table style=" float: right;">
	<tr>
        <td>
<!--            <input class="but" type="submit" name="yt0" value="提 交" />        -->
                <?php
                       echo CHtml::ajaxSubmitButton('提交信息', CHtml::normalizeUrl(array('activityDetail/update','id'=>$model->id)), array(
                           'type' => 'POST',
                           'data' => 'js:jQuery(this).parents("form").serialize()+"&isAjaxRequest=1"',
                           'success' =>
                           'function(data){
//                              alert(data);
                                if(data==1){
                                          close();
                                          location.href = "/ex/sign/index.php/activity/clander";                                   
                                }else{
                                            
                                            var d_t=eval("("+data+")");

                                            $.each(d_t,function(k,v){
                                                
                                                  $("#"+k+"_em_").html("<span>"+v+"</span>");
                                            });

                                            close();                                    
                                }
                                  }'
                               ), array(
                            'id' => 'ajaxSubmit',
                            'name' => 'ajaxSubmit',
                            'class'=>'but'                           

                       ));
                       ?>             
        </td>
        <td>
            <input class="but" type="button" onclick="delete_model(<?php echo $model->id; ?>)" value="删除活动" />        
        </td>   
        <td>
            <input class="but" type="button" name="yt0" onclick="stop_model(<?php echo $model->id; ?>)" value="截止报名" />        
        </td>          
    </tr>              
        </table>
</div>
<!---->
<div class="nTab" style=" margin-top: 50px;">
    <div class="TabTitle" style="width: 100%; text-align: center;" >
         <ul id="myTab">
                <li class="active" onclick="nTabs(this,0);">报名用户</li>
                <li class="normal" onclick="nTabs(this,1);">儿童信息</li>
                <li class="normal" onclick="nTabs(this,2);">商品销售情况</li>
                <li class="normal" onclick="nTabs(this,3);">用户消费情况</li>
                <li class="normal" onclick="print(<?php echo $model->id; ?>);">打印用户列表</li>
        </ul>
    </div>
    <div class="TabContent">
        <div id="myTab_Content0">
            <iframe frameborder="0"  width=100% height=500px src="<?php echo Yii::app()->createUrl('party/adminClander',array('detail_id'=>$model->id)) ?>">
            </iframe>
        </div>
        <div id="myTab_Content1" class="none">
            <iframe frameborder="0"  width=100% height=500px src="<?php echo Yii::app()->createUrl('children/adminClander',array('detail_id'=>$model->id)) ?>">
            </iframe>
        </div>
        <div id="myTab_Content2" class="none">
            <iframe frameborder="0"  width=100% height=500px src="<?php echo Yii::app()->createUrl('sale/adminClander',array('ad_id'=>$model->id)) ?>">
            </iframe>
        </div>
        <div id="myTab_Content3" class="none">
            <iframe frameborder="0"  width=100% height=500px src="<?php echo Yii::app()->createUrl('sale/partyClander',array('detail_id'=>$model->id)) ?>">
            </iframe>
        </div>
<!--        <div id="myTab_Content4" class="none">
            <iframe frameborder="0"  width=100% height=500px src="<?php echo Yii::app()->createUrl('default/print',array('detail_id'=>$model->id)) ?>">
            </iframe>
        </div>            -->
    </div>
</div>

    <script>           
        function set_time(id){
            $("#"+id).datetimepicker({
                showSecond: true,
                dateFormat:'yy-mm-dd',
                timeFormat: 'hh:mm:ss',
                stepHour: 1,
                stepMinute: 1,
                stepSecond: 1
            });             
        }
//        var line_count=$('#line_count').html();
//        for(var i=1;i<=line_count;i++){
//            set_time("go_time_model_"+i);
//        }
        //日历控件
        set_time("ActivityDetail_start");
        set_time("ActivityDetail_end");       
        set_time("ActivityDetail_clander_start");  
        set_time("ActivityDetail_clander_end");
        var add_id=1;
        function addList(){
//            var td= document.createElement("td"); 
            var td= document.createElement("td");
            var temp = hereDoc(function () {/*
                    <div>
                        <table style="background: #F0F0F0;" >
                            <tr style="background: #F0F0F0;">
                                <td></td>
                                <td align="right"><image onclick="clear_div(add_id)" style="width:1.5em; margin-left: 15em;"src=" <?php echo Yii::app()->baseUrl?>/images/del.png" /></td>
                            </tr>   
                            <tr style="background: #F0F0F0;">
                                <td align="right"><?php echo $form->labelEx($modelB,'car_id'); ?></td>
                                <td>
                                    <?php echo $form->dropDownList($modelB,'car_id[]',CHtml::listData(Carinfo::model()->findAll(), 'id', 'code'),
                                        array('empty'=>'-----请选择----','style'=>'float: left;')); ?>                                 
                                    <?php echo $form->error($modelB,'car_id'); ?>
                                </td>
                            </tr>

                            <tr style="background: #F0F0F0;">
                                <td align="right"><?php echo $form->labelEx($modelB,'go_time'); ?></td>
                                <td>
                                    <?php echo $form->textField($value,'go_time[]',array('size'=>15,'maxlength'=>255,'class'=>'fl input')); ?>
                                    <?php echo $form->error($modelB,'go_time'); ?>
                                </td>
                            </tr>

                            <tr style="background: #F0F0F0;">
                                <td align="right"><?php echo $form->labelEx($modelB,'position_id'); ?></td>
                                <td>
                                    <?php echo $form->dropDownList($modelB,'position_id[]',CHtml::listData(Position::model()->findAll(), 'id', 'address'),
                                        array('empty'=>'-----请选择----','style'=>'float: left;')); ?> 
                                    <?php echo $form->error($value,'position_id'); ?>
                                </td>
                            </tr>

                            <tr style="background: #F0F0F0;">
                                <td align="right"><?php echo $form->labelEx($modelB,'staff'); ?></td>
                                <td>
                                    <?php echo $form->dropDownList($modelB,'staff[]',CHtml::listData(Staff::model()->findAll(), 'id', 'username'),
                                        array('empty'=>'-----请选择----','style'=>'float: left;')); ?> 
                                    <?php echo $form->error($modelB,'staff'); ?>
                                </td>
                            </tr>
                        </table>   
                    </div>     
                    */});
//                    var new_id="clader_go_time"+add_id;
                    temp=temp.replace("add_id",add_id);
//                    temp=temp.replace("clader_go_time",new_id);
//                    td.id='add_line_'+add_id;
//                    td.innerHTML=' ';
                    td.innerHTML=temp;
                    td.id='add_lines_'+add_id;
                    //document.getElementById("ch_list").innerHTML= temp;
//                    document.getElementById("ch_list").insertBefore(td,null);     
                    ch=document.getElementById("ch_list");
//                    document.getElementById("ch").insertBefore(td,ch);  
                    document.getElementById("ch").insertBefore(td,ch);   
//                    set_time(new_id);  
                    add_id+=1;
        }
        function clear_div(id){
//                $("#add_line_"+id).html("");
//                $("#add_line_"+id).remove();
                $("#add_lines_"+id).html("");
                $("#add_lines_"+id).remove();                
        } 
        function nTabs(thisObj, Num) {
            if (thisObj.className == "active") return;
            var tabList = document.getElementById("myTab").getElementsByTagName("li");
            for (i = 0; i < tabList.length; i++) {//点击之后，其他tab变成灰色，内容隐藏，只有点击的tab和内容有属性
                if (i == Num) {
                    thisObj.className = "active";
                    document.getElementById("myTab_Content" + i).style.display = "block";
                } else {
                    tabList[i].className = "normal";
                    document.getElementById("myTab_Content" + i).style.display = "none";
                }
            }
        }
        function hereDoc(f) {　
            return f.toString().replace(/^[^\/]+\/\*!?\s?/, '').replace(/\*\/[^\/]+$/, '');
        }        
        //删除活动
        function delete_model(id){
            window.location.href="<?php echo Yii::app()->baseUrl?>/index.php/activityDetail/delete_model?id="+id;
        }
        //打印
        function print(detail_id){
            window.open('<?php echo Yii::app()->baseUrl?>/index.php/party/print?detail_id='+detail_id);
        }  
        //截止报名
        function stop_model(id){
            window.location.href="<?php echo Yii::app()->baseUrl?>/index.php/activityDetail/stop_model?id="+id; 
        }        
    </script> 
  <?php 
        if(Yii::app()->user->getFlash('stop')){
        echo "<script>art.dialog({icon:'succeed',content:'当前活动已截止！',time:2});</script>";
        }  
        if(Yii::app()->user->getFlash('delete_error')){
        echo "<script>art.dialog({icon:'error',content:'不能删除已开始的活动！',time:2});</script>";
        }
        if(Yii::app()->user->getFlash('success')){
        echo "<script>art.dialog({icon:'succeed',content:'操作成功！',time:2});</script>";  
        }
    ?>    
<?php $this->endWidget(); ?>
<!--表单内容-->